home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1993 by Jon Dart. All Rights Reserved.
-
- #include "hint.h"
- #include "search.h"
- #include "globals.h"
- #include "notation.h"
- #include "util.h"
-
- Move HintDialog::hintMove;
-
- HintDialog::HintDialog(WPWin *pwin, Board &board) :
- WPDialogModal("Hint", pwin, NULL, NULL),
- the_board(board),
- parent(pwin),
- next_move(0),
- num_moves(0)
- {
- createWin();
- }
-
- void HintDialog::initDlg()
- {
- const HWND hDlg = getHwnd();
- move_text = GetDlgItem(hDlg,IDP_HINT_TEXT);
- compute_hint();
- }
-
- void HintDialog::compute_hint()
- {
- // we keep a list of the hint moves generated so far.
- if (!moves[next_move].IsNull())
- {
- hintMove = moves[next_move];
- }
- else
- {
- WPWaitCursor wait = parent;
- num_moves = opening_book->book_moves(the_board,moves,
- Constants::MAX_HINT_MOVES);
- if (!num_moves)
- {
- // no book move, must search:
- Search searcher;
- num_moves = searcher.hints(the_board,moves,
- Constants::MAX_HINT_MOVES);
- }
- hintMove = moves[0];
- }
- if (!hintMove.IsNull())
- {
- char result[20];
- Notation::Image(the_board,hintMove,result);
- SetWindowText(move_text,result);
- ++next_move;
- if (next_move >= num_moves) next_move = 0;
- }
- }
-
- BOOL HintDialog::command(int id, WORD msg)
- {
- switch (id)
- {
- case IDP_ANOTHER:
- compute_hint();
- return TRUE;
- default:
- break;
- }
- return WPDialogModal::command(id, msg);
- }
-